package group.hhsw.purchase.utils;

import java.lang.reflect.Field;

public class CombineBeans {

    public static <T> void copyNotNull(T source, T target) {
        if (source == null || target == null) return;
        if (!source.getClass().equals(target.getClass())) return;

        Field[] fields = source.getClass().getDeclaredFields();
        for (Field field : fields) {
            try {
                field.setAccessible(true);
                Object value = field.get(source);
                if (value != null) {
                    field.set(target, value);
                }
                field.setAccessible(false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
